const {extractMethods, calculateIfCondition, writeResultsToCSV} = require("./utils");


function main(ids, fileName, fileContent) {
    const methods = extractMethods(fileContent);

    const resultToWrite = [];
    ids.forEach(id => {
        methods.forEach((method => {
            if (method.body.includes(id)) {
                const methodBodyLinesArr = method.body.split('\n');
                methodBodyLinesArr.forEach((line, index) => {
                    if (line.includes(id)) {
                        const conditions = calculateIfCondition(index, methodBodyLinesArr)
                        const result = methodBodyLinesArr[index];
                        resultToWrite.push({id, condition: conditions.join('\n'), action: result, method: method.name})
                    }
                })
            }
        }))
    })
    const headerObj = [
        {id: 'id', title: 'ID'},
        {id: 'condition', title: 'Условие'},
        {id: 'action', title: 'Что произойдет'},
        {id: 'method', title: 'Метод класса'}
    ]
    writeResultsToCSV(resultToWrite, headerObj, fileName +'.cs');
}

module.exports = {lookIterateWriteCs: main};
